package view;

import java.util.Scanner;

public class MainView {
    private static MainView singleton;
    private MainView() {
        deptView = DeptView.getInstance();
        roleView = RoleView.getInstance();
        userView = UserView.getInstance();
    }
    public static MainView getInstance() {
        if(singleton == null) {
            singleton = new MainView();
        }
        return singleton;
    }
    public static final String MENU = """
            ---------------------
                  RBAC系统
            ---------------------
            |     0...退出系统    |
            |     1...部⻔管理    |
            |     2...⻆⾊管理    |
            |     3...⽤户管理    |
            ---------------------
            请输⼊选项：""";

    public static Scanner input;

    static {
        input = new Scanner(System.in);
    }


    /**
     * 显示主界⾯
     * 实现菜单循环显示及功能选择
     */
    private final DeptView deptView;
    private final RoleView roleView;
    private final UserView userView;

    public void show() {
        String menuChoice; // ⽤于存储⽤户输⼊的选项
        do {
            System.out.print(MENU);
            menuChoice = input.nextLine();
            switch (menuChoice) {
                case "0" -> System.out.println("成功退出系统，欢迎再次使⽤！");
                case "1" -> deptView.show();
                case "2" -> roleView.show();
                case "3" -> userView.show();
                default -> System.out.println("输⼊⾮法，请输⼊正确的菜单编号！");
            }
        } while (!"0".equals(menuChoice));
        input.close();
    }


}







